package linkedhashmap;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * HashSet的子类LinkedHashSet
 * HashMap的子类LinkedHashMap
 * LinkedHashMap特点:
 *   1.LinkedHashMap的key依然不重复(key的唯一性依据的是hashCode()方法和equals()方法)
 *   2.LinkedHashMap可以保证key的存取顺序一致(value顺序自然也一致,因为key与value值是一一对应的)
 */
public class LinkedHashMapDemo01 {
    public static void main(String[] args) {
        HashMap<Integer, String> hm = new HashMap<>(){{
            put(42, "abc");
            put(42, "def");
            put(52, "mn");
            put(1, "ghk");
        }};
        System.out.println(hm);//{1=ghk, 52=mn, 42=def}
        System.out.println("-----------------");

        LinkedHashMap<Integer, String> lhm = new LinkedHashMap<>(){{
            put(42, "abc");
            put(42, "def");
            put(52, "mn");
            put(1, "ghk");
        }};
        System.out.println(lhm);//{42=def, 52=mn, 1=ghk}

    }
}
